package oojo.data.spec;

import java.util.Set;
import java.util.HashSet;
import java.util.Collections;

/**
 * Search entities' properties for a certain value.
 */
public class Filter {

    public static final int STARTS = 1;
    public static final int ENDS   = 2;
    
    private int mode;
    private String value;
    private Set<String> properties;
    
    public Filter() {}
    
    public Filter(String value, String[] properties) {
        setValue(value);
        Collections.addAll(getProperties(), properties);
    }
    
    /**
     * Match mode: 0) has anywhere, 1) starts with, 2) ends with
     */
    public int getMode() {
        return mode;
    }
    
    public void setMode(int mode) {
        this.mode = mode;
    }
    
    /**
     * The value that will be matched.
     */
    public String getValue() {
        return value;
    }
    
    public void setValue(String value) {
        this.value = value;
    }
    
    /**
     * The properties that will be used in search.
     */
    public Set<String> getProperties() {
        if (properties == null) {
            properties = new HashSet<String>();
        }
        
        return properties;
    }
    
    public void setProperties(Set<String> properties) {
        this.properties = properties;
    }
}
